package homeTask3;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class TestSorting {
	public static void main(String[] args) throws IOException, InterruptedException {
        Process proc = null;
        long startTime = System.currentTimeMillis();
        
        proc = Runtime.getRuntime().exec(args[0] + " " + args[1] + " " + args[2]);
        proc.waitFor(); //waiting for our proccess to end
        
        long time = System.currentTimeMillis() - startTime;

        System.out.print("Program works for: " + time + " miliseconds. Sort was ");
        if(compareFiles(args[2], args[3]))
        	System.out.print("successful");
        else
        	System.out.println("failed");
    }
	
	static boolean compareFiles(String filePath1, String filePath2){
		try{
			File f1 = new File(filePath1);
			File f2 = new File(filePath2);
			
			if(f1.length() == f2.length()){
				FileInputStream fis1 = new FileInputStream(f1);
				FileInputStream fis2 = new FileInputStream(f2);
				 
				while(true){
					int a = fis1.read();
					int b = fis2.read();
					if(a != b)
						return false;
					if(a == -1)
						return true;
				}
			}
			else
				return false;
		}catch(Exception e){
			e.printStackTrace();
		}
		return false;
	}
}
















